<?php

/**
 * @version		1.0.0 gerenciador_de_arquivos $
 * @package		gerenciador_de_arquivos
 * @copyright	Copyright © 2012 - All rights reserved.
 * @license		GNU/GPL
 * @author		Edio Hanoway Kepke
 * @author mail	hanoway12@gmail.com 
 */
require_once(dirname(__FILE__).DS.'autor.php');
class AutorDAO 
{
    private static $autorDAO;

    private $db;
    
    private $table = "mod_file_autor";

    private function __construct() { }
    
    public static function instance()
    {
        if(is_null(self::$autorDAO))
        {
            self::$autorDAO = new AutorDAO();                       
       }                       
       return self::$autorDAO;
    }
    
    public function setDb($db) { $this->db = $db; }
    
    
    public function insert($autor, $getId = false)
    {
        $autorOBJ = new Autor($autor);
        try 
        {
            $salvo = $this->db->insertObject($this->table, $autorOBJ);
                                    
            if($getId)
            {
                return $this->db->insertid();                
            }
            
            return $salvo;
        } 
        catch (Exception $exc) 
        {
            return false;
        }   
    }
    
    public function update($autor)
    {
                
    }
    
    public function delete($autor)
    {
                
    }
    
    public function select($id)
    {
                
    }  
    
    public function selectObject($assunto)
    {        
        //$this->db = JFactory::getDbo();
        $query = $this->db->getQuery(true);
        $query->select('*')->from("mod_file_autor");                        
        $query->where("nome = '".trim($assunto)."'");
        $this->db->setQuery($query);        
        return $this->db->loadObject();
    }
    
     public function selectLike($condition)
    {         
        //$this->db = JFactory::getDBO();
        $query = $this->db->getQuery(true);
        $query->select('nome')->from("mod_file_autor");
        $query->where("nome like'".trim($condition)."'");
        $this->db->setQuery($query);
        $autores = $this->db->loadResultArray();
        
        if(count($autores) != 0)
        {
            return $autores;
        }
        
        return false;
    }
}
?>
